﻿using System.Collections.Generic;
using Microsoft.Data.Schema.ScriptDom.Sql;
//using System.Diagnostics;
using System;
using System.IO;
using System.Text.RegularExpressions;


namespace Neznayka
{
    internal class EnforceNamedConstraintDeclareTableVisitor : TSqlConcreteFragmentVisitor
    {
        private List<TSqlFragment> _objects;

        #region ctor
        public EnforceNamedConstraintDeclareTableVisitor()
        {
            _objects = new List<TSqlFragment>();
        }
        #endregion

        #region properties
        public List<TSqlFragment> Objects
        {
            get { return _objects; }
        }
        #endregion

        #region overrides
        public override void ExplicitVisit(DeclareTableStatement node)
        {
            _objects.Add(node);
        }
        public override void ExplicitVisit(CreateTableStatement node)
        {
            if ( node.SchemaObjectName.BaseIdentifier.Value.StartsWith(@"#")) {
                _objects.Add(node);
            }
        }
        public override void ExplicitVisit(AlterTableAddTableElementStatement node)
        {
            if (node.SchemaObjectName.BaseIdentifier.Value.StartsWith(@"#"))
            {
                _objects.Add(node);
            }
        }
        public override void ExplicitVisit(AlterTableConstraintModificationStatement node)
        {
            if (node.SchemaObjectName.BaseIdentifier.Value.StartsWith(@"#"))
            {
                _objects.Add(node);
            }
        }
        public override void ExplicitVisit(CreateFunctionStatement node)
        {
            if ( node.ReturnType != null  )
            {
                TableValuedFunctionReturnType chk  = node.ReturnType as TableValuedFunctionReturnType;
                SelectFunctionReturnType      chk2 = node.ReturnType as SelectFunctionReturnType;
                if (chk != null || chk2 != null)
                {
                    _objects.Add(node.ReturnType);
                }
            }
        }
        public override void ExplicitVisit(AlterFunctionStatement node)
        {
            if (node.ReturnType != null)
            {
                TableValuedFunctionReturnType chk  = node.ReturnType as TableValuedFunctionReturnType;
                SelectFunctionReturnType      chk2 = node.ReturnType as SelectFunctionReturnType;
                if (chk != null || chk2 != null)
                {
                    _objects.Add(node.ReturnType);
                }
            }
        }

        #endregion

    }


}
